<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

class Inputs
{
	static private $instance;
	
	private $get_array = array();
	private $post_array = array();
	
	private function __construct()
	{
		foreach ($_GET as $k => $v)
		{
			$this->get_array[$k] = $this->RipData($v);
		}
		
		foreach ($_POST as $k => $v)
		{
			$this->post_array[$k] = $this->RipData($v);
		}
	}
	
	static function GetInstance()
	{
		if ( empty(self::$instance) )
		{
			self::$instance = new Inputs();
		}
		
		return self::$instance;
	}
	
	private function RipData($s)
	{
		if ( get_magic_quotes_gpc() == 1 )
		{
			$s = stripslashes($s);
		}
		
		$s = htmlspecialchars($s, ENT_QUOTES);
		
		return $s;
	}
	
	function Get($field, $default_value=null)
	{
		if ( array_key_exists($field, $this->get_array) )
		{
			return $this->get_array[$field];
		}
		else
		{
			return $default_value;
		}
	}
	
	function HasGetData($field)
	{
		if ( array_key_exists($field, $this->get_array) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function Post($field, $default_value=null)
	{
		if ( array_key_exists($field, $this->post_array) )
		{
			return $this->post_array[$field];
		}
		else
		{
			return $default_value;
		}
	}
	
	function HasPostData($field)
	{
		if ( array_key_exists($field, $this->post_array) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

?>